import { post, request } from "@/utils/request";
import {
  ICategoryEditData, IExternalConfigData, IExternalConfigItem, ITaskCategoryData,
  ITaskCategoryItem,
  ITaskEditData, ITaskInfoItem, ITaskInfoListData,
  ITaskListData,
  ITaskListItem, ITaskRecordData, ITaskRecordItem
} from "@/api/modules/taskCenter";
import ApiResult from "@/api/base/ApiResult";

/**
 * 获取任务列表
 */
export function getTaskList(data: ITaskListData): Promise<ApiResult<ITaskListItem[]>> {
  return request('merchant/task/info/pageTaskInfo', data)
}

/**
 * 获取对接系统列表
 */
export function getExternalConfigList(data: IExternalConfigData): Promise<ApiResult<IExternalConfigItem[]>> {
  return request('merchant/config/external/configList', data)
}

/**
 * 新建或编辑任务
 */
export function saveOrUpdateTask(data: ITaskEditData): Promise<ApiResult<any>> {
  return request('merchant/task/info/saveOrUpdateTaskInfo', data)
}

/**
 * 删除任务
 */
export function deleteTask(data: {id: number, name: string}): Promise<ApiResult<any>> {
  return request('merchant/task/info/deleteTaskInfo', data)
}

/**
 * 切换任务状态，启用禁用任务
 */
export function changeTaskStatus(data: {id: number}):Promise<ApiResult<any>> {
  return request('merchant/task/info/updateStatus',data)
}

/**
 * 获取任务分类
 */
export function getTaskCategory(data: ITaskCategoryData): Promise<ApiResult<ITaskCategoryItem[]>> {
  return request('merchant/task/type/typeInfoList', data)
}

/**
 * 获取任务分类树
 * @param data
 */
export function getTaskCategoryTree(data?: ITaskCategoryData):Promise<ApiResult<ITaskCategoryItem[]>> {
  return request('merchant/task/type/typeInfoTree', data)
}

/**
 * 批量修改任务信息
 * @param data
 */
export function saveOrUpdateTaskInfoMultiple(data: {id: number, categoryIds: string[]}[]):Promise<ApiResult<any>> {
  return request('merchant/task/info/saveOrUpdateTaskInfo/v140', data)
}

/**
 * 新建或编辑分类
 */
export function saveOrUpdateCategory(data: ICategoryEditData): Promise<ApiResult<any>> {
  return request('merchant/task/type/saveOrUpdateType', data)
}

/**
 * 删除分类
 */
export function deleteCategory(data: {id: number}): Promise<ApiResult<any>> {
  return request('merchant/task/type/deleteTypeInfo', data)
}

/**
 * 查询任务是否被引用
 * @param data
 */
export function checkTaskQuotation(data: {id: number}): Promise<ApiResult<{aBoolean: boolean}>> {
  return request('merchant/task/info/quote', data)
}

export function updateTaskCateStatus(data: {id: number}): Promise<ApiResult<any>> {
  return request('merchant/task/type/updateStatus', data)
}

/**
 * 获取任务记录
 */
export function getTaskUserInfo(data: ITaskRecordData): Promise<ApiResult<ITaskRecordItem[]>> {
  return request('merchant/task/user/pageTaskUserInfo', data)
}

/**
 * 获取所有任务信息
 */
export function getTaskInfoList(data: ITaskInfoListData): Promise<ApiResult<ITaskInfoItem[]>> {
  return request('merchant/task/info/taskInfoList', data)
}
